<template>
  <div class="users">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户据列表</el-breadcrumb-item>
      <!-- <el-breadcrumb-item>活动详情</el-breadcrumb-item> -->
    </el-breadcrumb>

    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary">主要按钮</el-button>
        </el-col>
      </el-row>
      <el-table :data="WeatherForecasts" border stripe style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="date" label="日期" width="160"></el-table-column>
        <el-table-column prop="summary" label="姓名" width="100"></el-table-column>
        <el-table-column prop="temperatureC" label="摄氏" width="80"></el-table-column>
        <el-table-column prop="temperatureF" label="华氏" width="80"></el-table-column>
        <el-table-column label="状态" width="80">
          <template slot-scope="scope">
            <!-- {{scope.row}} -->
            <el-switch v-model="scope.row.temperatureC" @change="changeState(scope.row)"></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
            <el-tooltip effect="dark" content="提示文字" placement="top">
              <el-button type="warning" icon="el-icon-setting" size="mini"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="criteria.pagenum"
        :page-sizes="[30, 50, 100, 400]"
        :page-size="criteria.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      users: [],
      WeatherForecasts: [],
      criteria: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      currentPage: 0
    }
  },
  methods: {
    async getWeatherForecastList () {
      const { data: res } = await this.$httpClient.get('WeatherForecast', this.criteria)
      // const res = await this.$httpClient.get('WeatherForecast', this.criteria)
      // console.log(res)
      this.WeatherForecasts = res
    },
    handleSizeChange (pageSize) {
      // console.log(pageSize)
      this.criteria.pagesize = pageSize
      this.getWeatherForecastList()
    },
    handleCurrentChange (page) {
      // console.log(page)
      this.criteria.pagenum = page
      this.getWeatherForecastList()
    },
    async changeState (row) {
      console.log(row)
      // const { data: res } = await this.$httpClient.put(`users/${row.id}/state/${row.state}`)
      // {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.4","title":"Not Found","status":404,"traceId":"|bc09fba6-46246f50f674b2ef."}
      row.id = 2
      const { data: res } = await this.$httpClient.put(`TodoItems/${row.id}`,
        { 'Id': 2, 'Name': 'dddd', 'IsComplete': true })
      if (res.meta.status !== 200) {
        row.state = !row.state
        return this.$message.error('ddd')
      }
      this.$message.success('更新成功')
    }
  },
  created () {
    this.getWeatherForecastList()
  }

}
</script>

<style lang="less" scoped>
.users {
  .el-card{
margin-top: 1rem;
  }
}
</style>
